class Admin::LinkController < Admin::BaseAdminController
  

  def list
    @links = @blog.links.paginate :per_page => @@PER_PAGE, :page => params[:page],
      :order => :position
  end

  def create
    @link = Link.new(params[:link])
    if request.post? && @blog.links << @link
      redirect_to_default("Link created")
    end
  end

  def update
    @link = Link.find(params[:id])
    if request.post? && @link.update_attributes(params[:link])
      redirect_to_default("Link updated")
    end
  end

  def delete
    if request.post? && Link.destroy(params[:id])
      redirect_to_default("Link deleted")
    end
  end

  def move_up
    link = Link.find(params[:id])
    link.move_higher
    redirect_to_default(link.name + " moved up.")
  end

  def move_down
    link = Link.find(params[:id])
    link.move_lower
    redirect_to_default(link.name + " moved down.")
  end
  
  private 
  def redirect_to_default(notice = nil)
    flash[:notice] = notice unless notice.nil?
    redirect_to :action => :list
  end
end
